/*
 * Copyright (c) 2019.
 * http://www.ulabcare.com
 */

package com.mt.roll.passport.controller;

import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.dto.LoginUser;
import com.mt.roll.core.params.MobileParam;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.passport.params.BatchInvalidateSessionParam;
import com.mt.roll.passport.params.QueryLoginLogParam;
import com.mt.roll.passport.params.QuerySessionParam;
import com.mt.roll.passport.params.SessionParam;
import com.mt.roll.passport.service.SessionService;
import com.mt.roll.passport.vo.LoginLogVo;
import com.mt.roll.passport.vo.LoginSessionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author jiff
 * @date 2019-07-20
 * @since 1.0
 */
@RestController
@RequestMapping("session")
@Slf4j
@Validated
@Api(value = "会话接口", tags = "会话接口")
public class SessionController extends BaseController {
    @Autowired
    private SessionService sessionService;


    @PostMapping("list")
    @ApiOperation(value = "获取在线会话列表", notes = "获取在线会话列表")
    public R<PageVo<LoginSessionVo>> list(@RequestBody QuerySessionParam param) {
        return sessionService.list(param);
    }

    @PostMapping("listLog")
    @ApiOperation(value = "获取会话日志列表", notes = "获取会话日志列表")
    public R<PageVo<LoginLogVo>> listLog(@RequestBody QueryLoginLogParam param) {
        return sessionService.listLog(param);
    }

    @PostMapping(value = "invalidateSession")
    @ApiOperation(value = "注销用户会话", notes = "返回被注销的用户会话ID")
    public R<String> invalidateSession(@RequestBody SessionParam param) {
        return sessionService.invalidateSession(param);
    }

    @PostMapping(value = "batchInvalidateSession")
    @ApiOperation(value = "批量注销用户会话", notes = "返回被注销的用户会话ID")
    public R<List<String>> batchInvalidateSession(@RequestBody BatchInvalidateSessionParam param) {
        return sessionService.batchInvalidateSession(param);
    }

    @PostMapping(value = "invalidateSessionByMobile")
    @ApiOperation(value = "注销用户会话", notes = "返回被注销的用户会话ID")
    public R<List<String>> invalidateSession(@RequestBody MobileParam param) {
        return sessionService.invalidateSession(param);
    }

    @PostMapping(value = "invalidateAllSession")
    @ApiOperation(value = "注销所有平台用户会话", notes = "返回被注销的用户会话ID")
    public R<List<String>> invalidateSession() {
        return sessionService.invalidateAllPlatformSession();
    }


    @PostMapping(value = "getSession")
    @ApiOperation(value = "获取登录用户", notes = "返回登录用户信息")
    public R<List<LoginUser>> getLoginSession(@RequestBody MobileParam param) {
        return sessionService.getLoginSession(param);
    }

}
